﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using QLTV.Public;

namespace QLTV.DAL
{
    public class NXBDAL
    {
        ConnectionData connect;
        public DataTable TimTheoTen(NXBDTO nxbDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@search";
                value[0] = nxbDTO.TenNXB;
                return connect.GetData("NXB_TimTheoTen", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable LoadDuLieuCotMaNXB(NXBDTO nxbDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@manxb";
                value[0] = nxbDTO.MaNXB;
                return connect.GetData("NXB_LoadDuLieuCotMaNXB", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable Load()
        {
            try
            {
                connect = new ConnectionData();
                return connect.GetData("NXB_Load");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public int nhapNXB(NXBDTO nxbDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 5;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@manxb";
                value[0] = nxbDTO.MaNXB;
                name[1] = "@tennxb";
                value[1] = nxbDTO.TenNXB;
                name[2] = "@diachi";
                value[2] = nxbDTO.DiaChi;
                name[3] = "@email";
                value[3] = nxbDTO.Email;
                name[4] = "@sdt";
                value[4] = nxbDTO.Sdt;
                return connect.UpdateData("NXB_InsertUpdate", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public int Xoa(NXBDTO nxbDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@manxb";
                value[0] = nxbDTO.MaNXB;
                return connect.UpdateData("NXB_Xoa", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
    }
}
